<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>当前助理学员信息</title>
<link href="../easyui/themes/default/easyui.css" rel="stylesheet"
	type="text/css" />
<link href="../easyui/themes/icon.css" rel="stylesheet" type="text/css" />
<script src="../easyui/jquery.min.js" type="text/javascript"></script>
<script src="../easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="../js/jquery-form.js" type="text/javascript"></script>
<!-- <script type="text/javascript" src="../js/checkLogin.js"></script> -->
<script type="text/javascript">
	//添加新助管
	function newAststu() {
		$('#dlg').dialog('open').dialog('setTitle', '创建新助管');
		$('#fm').form('clear');
		url = '/studentmanagement/aststu/add.do';
	}
	//修改助管信息
	function edit(index) {
		var row = $('#list_data').datagrid('getData').rows[index];
		//alert(row);
		$('#dlg').dialog('open').dialog('setTitle', '修改助管信息');
		$('#fm').form('clear');
		$('#fm').form('load', row);
		url = '/studentmanagement/aststu/update.do';
	}
	//删除一条助管信息
	function deleteAststu(index) {
		var row = $('#list_data').datagrid('getData').rows[index];
		if (row) {
			$.messager.confirm('提示', '确定删除吗?', function(r) {
				if (r) {
					$.post('/studentmanagement/aststu/delete.do', {
						id : row.id
					}, function(result) {
						if (result.status == 1) {
							$('#list_data').datagrid('reload'); // reload the user data
						} else {
							$.messager.show({ // show error message
								title : 'Error',
								msg : result.message
							});
						}
					}, 'json');
				}
			});
		}
	}

	//批量导入按钮事件
	function updateAststu() {
		//alert($("#searchUnitId").val());
		$('#dlg_upload').dialog('open').dialog('setTitle', '上传文件');
	}
	//上传excel
	function uploadExcel() {
		//得到上传文件的全路径  
		var fileName = $('#uploadExcel').val();
		//alert(fileName);

		//进行文件后缀校验
		if (fileName == "") {
			$.messager.alert('提示', '请选择上传文件！', 'info');
		} else {
			//对文件格式进行校验  
			var d1 = /\.[^\.]+$/.exec(fileName);
			if (d1 == ".xls" || d1 == ".xlsx") {
				var options = {
					url : '/studentmanagement/aststu/upload.do',
					success : function(data) {
						$.messager.alert('Info', data.message, 'info');
						$('#list_data').datagrid('reload'); // reload the user data
						$('#uploadExcel').val('');
					},
					error : function() {
						$.messager.alert('Error', "服务器内部错误", 'error');
					}
				};
				$('#fm_aststu_upload').ajaxSubmit(options);
			} else {
				$.messager.alert('错误', '请选择excel文件上传！', 'error');
				$('#uploadExcel').val('');
			}
		}

	}
	//批量删除已选
	function deleteSelected() {
		//获取已选的几行数据，传递给服务器删除.
		var ids = "";
		var rows = $('#list_data').datagrid('getSelections');
		if (rows.length > 0) {
			for (var i = 0; i < rows.length; i++) {
				if (i != rows.length - 1)
					ids += (rows[i].id + ",");
				else
					ids += rows[i].id;
			}
			$.messager.confirm('提示', '确定删除吗?', function(r) {
				if (r) {
					$.post('/studentmanagement/aststu/deleteSelections.do', {
						ids : ids
					}, function(result) {
						if (result.status == 1) {
							$('#list_data').datagrid('reload'); // reload the user data
						} else {
							$.messager.show({ // show error message
								title : 'Error',
								msg : result.message
							});
						}
					}, 'json');
				}
			});
		} else {
			$.messager.alert('错误', '请选择一行或几行数据！', 'error');
		}

	}

	//已选转为历史

	//点击查询按钮时添加查询条件给请求
	function doSearch() {
		$('#list_data').datagrid('load', {
			id : $("#searchId").val(),
			name : $("#searchName").val(),
			unitId : $("#searchUnitId").val()
		});
	}

	//保存修改
	function saveAststu() {
		$('#fm').form('submit', {
			url : url,
			onSubmit : function() {
				return $(this).form('validate');
				var selectValue = $("#unidId").val();
				if (!selectValue) {
					alert("请选择一个单位");
					return false;
				}
			},
			success : function(result) {
				if (result.status == 0) {
					$.messager.show({
						title : 'Error',
						msg : result.message
					});
				} else {
					$('#dlg').dialog('close'); // close the dialog
					$('#list_data').datagrid('reload'); // reload the user data
				}
			},
			error : function() {
				$.messager.show({
					title : 'Error',
					msg : "修改失败"
				});
			}
		});

	}
</script>
</head>
<body>
	<!-- 工具框 -->
	<div id="tb" style="padding: 3px">
		<span>学号:</span> <input id="searchId"
			style="line-height: 20px; border: 1px solid #ccc"> <span>姓名:</span>
		<input id="searchName"
			style="line-height: 20px; border: 1px solid #ccc"> <span>所在单位:</span>
		<select id="searchUnitId" style="width: 200px;">
		</select> <a iconCls="icon-search" href="#" class="easyui-linkbutton"
			plain="true" onclick="doSearch()">查询</a> <br />
		<hr />
		<a href="javascript:newAststu()" class="easyui-linkbutton"
			iconCls="icon-add" plain="true">添加新助管</a> <a
			href="javascript:updateAststu()" class="easyui-linkbutton"
			iconCls="icon-add" plain="true">批量导入</a><a
			href="javascript:deleteSelected()" class="easyui-linkbutton"
			iconCls="icon-add" plain="true">批量删除已选</a><a
			href="javascript:selectedToHistory()" class="easyui-linkbutton"
			iconCls="icon-add" plain="true">已选转为历史</a>
	</div>
	<!-- 数据表框 -->
	<table id="list_data">
	</table>
	<script type="text/javascript">
		$("#searchUnitId").append("<option value=''>-----------</option>");
		$.ajax({
			url : "/studentmanagement/unit/list.do",
			cache : false,
			async : false,
			dataType : "json",
			success : function(result) {
				for (var i = 0; i < result.length; i++) {
					$("#searchUnitId").append(
							"<option value='"+result[i].id+"'>"
									+ result[i].name + "</option>");
				}
			}
		});
		$('#list_data')
				.datagrid(
						{
							title : '助管信息列表',
							iconCls : 'icon-save',//图标 
							width : 'auto',
							height : 'auto',
							nowrap : false,
							autoRowHeight : false,
							striped : true,//设置为true将交替显示行背景。
							border : true,
							collapsible : false,//是否可折叠的 
							fitColumns : true,
							checkOnSelect : false,
							fit : true,//自动大小 
							url : '/studentmanagement/aststu/listBySelectionAndPage.do',
							//sortName : 'id',
							//sortOrder : 'asc',
							remoteSort : false,
							idField : 'id',
							singleSelect : false,//是否单选  设置为true将只允许选择一行。
							pagination : true,//设置true将在数据表格底部显示分页工具栏。 
							rownumbers : true,//行号 设置为true将显示行数。
							queryParams : {
								id : $("#searchId").val(),
								name : $("#searchName").val(),
								unitId : $("#searchUnitId").val()
							},
							frozenColumns : [ [ {
								field : 'ck',
								checkbox : true
							} ] ],
							columns : [ [
									{
										field : 'id',
										title : '编号',
										width : 100,
									//sortable : true
									},
									{
										field : 'name',
										title : '姓名',
										width : 100,
									//sortable : true
									},
									{
										field : 'unitName',
										title : '单位名称',
										width : 100
									},
									{
										field : 'officeName',
										title : '设岗科室名称',
										width : 100
									},
									{
										field : 'tel',
										title : '联系电话',
										width : 100
									},
									{
										field : 'bankNo',
										title : '建行卡号',
										width : 100
									},
									{
										field : 'action',
										title : '操作',
										width : 70,
										align : 'center',
										formatter : function(value, row, index) {
											var s = '<button class="editRow" onclick="edit('
													+ index + ')">修改</button>';
											var c = '<button class="editRow" onclick="deleteAststu('
													+ index + ')">删除</button>';
											return s + c;
										}
									} ] ],
							toolbar : '#tb'
						});
		//设置分页控件 
		var p = $('#list_data').datagrid('getPager');
		$(p).pagination({
			//showPageList:false,
			pageSize : 10,//每页显示的记录条数，默认为10 
			pageList : [ 5, 10, 15 ],//可以设置每页记录条数的列表 
			beforePageText : '第',//页数文本框前显示的汉字 
			afterPageText : '页    共 {pages} 页',
			displayMsg : '当前显示 {from} - {to} 条记录   共 {total} 条记录'
		});
	</script>

	<!-- 下面的是创建或编辑对话框 -->
	<div Closed="true" id="dlg" class="easyui-dialog"
		data-options="modal:true,closed:true"
		style="width: 400px; height: 300px; padding: 10px 20px"
		buttons="#dlg-buttons">
		<div class="ftitle">助管详细信息填写</div>
		<form id="fm" method="post">
			<table>
				<tr>
					<td>编 号:</td>
					<td><input name="id" class="easyui-validatebox"
						required="true"></td>
				</tr>
				<tr>
					<td>姓名:</td>
					<td><input name="name" class="easyui-validatebox"
						required="true">
				</tr>
				<tr>
					<td>所在单位:</td>
					<td><select id="unitId" style="width: 200px;" name="unitId"
						class="easyui-validatebox" required="true">
					</select>
				</tr>
				<script type="text/javascript">
					$
							.ajax({
								url : "/studentmanagement/unit/list.do",
								cache : false,
								async : true,
								dataType : "json",
								success : function(result) {
									for (var i = 0; i < result.length; i++) {
										$("#unitId").append(
												"<option value='"+result[i].id+"'>"
														+ result[i].name
														+ "</option>");
									}
								}
							});
				</script>
				<tr>
					<td>设岗科室名称:</td>
					<td><input name="officeName">
				</tr>
				<tr>
					<td>联系电话:</td>
					<td><input name="tel">
				</tr>
				<tr>
					<td>建行卡号:</td>
					<td><input name="bankNo" class="easyui-validatebox"
						required="true" />
				</tr>

			</table>
		</form>
	</div>
	<!-- 创建或编辑对话框的里面的按钮 -->
	<div id="dlg-buttons">
		<a href="#" class="easyui-linkbutton" iconCls="icon-ok"
			onclick="saveAststu()">保存</a> <a href="#" class="easyui-linkbutton"
			iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">退出</a>
	</div>
	<!-- 创建批量导入对话框 -->
	<div Closed="true" id="dlg_upload" class="easyui-dialog"
		data-options="modal:true,closed:true"
		style="width: 400px; height: 200px; padding: 10px 20px">
		<div class="ftitle">批量导入</div>
		<hr />
		<form id="fm_aststu_upload" method="post"
			enctype="multipart/form-data"
			action="/studentmanagement/aststu/upload.do">
			选择文件： <input id="uploadExcel" name="uploadExcel" type="file" /> <a
				href="#" class="easyui-linkbutton" style="width: 40px"
				onclick="uploadExcel()">上传</a>

		</form>
		<hr />
		<div>
			<span>点击下载模板</span><a href="#">模板</a>
		</div>
	</div>
</body>

</html>
